<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ include file="global.jsp" %>
<%
Connection con = null; 
PreparedStatement pstmt = null; 
Statement st = null; 
ResultSet rs = null;
String matchId = (String)session.getAttribute("matchId");
session.setAttribute("matchId", matchId);
if(matchId!=null){
	int SNo = 0;
	int id = 0;
	String player = null;
	String runs = null;
	String wickets = null;
	String mom = null;
	String fiftyRuns = null;
	String fourWkts = null;
	String winner = request.getParameter("winner");
	String sixesWinner = request.getParameter("sixesWinner");
	String manOfMatch = request.getParameter("manOfMatch");
	String sixes = request.getParameter("sixes");
	session.setAttribute("sixesWinner", sixesWinner);
	session.setAttribute("sixes", sixes);
	
	int total = 0;
	try{
		Class.forName(db_driver);
		con = DriverManager.getConnection(db_url, db_user, db_password);
		
		st=con.createStatement();
		String str = "select count(*) from matchresults where matchId = '"+matchId+"'";
		rs=st.executeQuery(str);
		while(rs.next()){
		   SNo = rs.getInt(1);
		}
		if(SNo==0){
			 String query = "insert into matchResults(matchId, winner, mom, sixesWinner, sixes)values(?,?,?,?,?)";
			 pstmt = con.prepareStatement(query); 
			 pstmt.setString(1, matchId);
			 pstmt.setString(2, winner);
			 pstmt.setString(3, manOfMatch);
			 pstmt.setString(4, sixesWinner);
			 pstmt.setString(5, sixes);
			 pstmt.executeUpdate();
		}
		pstmt.close();
		rs.close();
		st.close();
		session.setAttribute("resposeText","Scores Updated");
	}
		catch (Exception e1){
		e1.printStackTrace();
	} 
	finally{
		
	}
}
%>
<jsp:forward   page="updateVoterPoints.jsp"/>
</body>
</html>